/**
 * Copyright (c) 2012, Brent Mucci, Ken Anderson
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright notice, 
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 **/

#ifndef MCL_VISUALIZER_H
#define MCL_VISUALIZER_H

#include <string>

#include "mcl_common.h"
#include "mcl_image.h"
#include "mcl_image_resize.h"

#ifdef USE_SFML
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#endif

namespace mcl
{

// Handles the windowing, visualization, and interactive component of the application.
// This is a light wrapper around SFML.
// If SFML is disabled, this class will output text to command line.
class Visualizer
{
public:
	// Constructor/deconstructor
	// windowWidth and windowHeight specify the initial size of the window.
	// The window is split into NxN cells, where N = windowCells.
	Visualizer(int windowWidth, int windowHeight, int windowCells);
	~Visualizer();

	// Returns true if the window is opened or returns true if not using SFML.
	bool isOpened();

	// Draw an image to the specified cell.
	void drawImage( const Image &image, int cellColumn=0, int cellRow=0 );

	// Print a text string to command line
	// If using SFML, also print to screen and replace existing text.
	void print(const std::string &text);

	// Clear the window.
	void clear();

	// Display the window (actually swaps image buffers)
	void display();

	// Handle keypress and mouse events.  
	// Currently no variable references are passed in, but this may change in the future.
	void handleEvents();

#ifdef USE_SFML
private:
	int m_cellWidth;
	int m_cellHeight;
	int m_windowCells;
	float m_zoomFactor;
	sf::RenderWindow m_app;
	sf::Image m_sfImage;
	sf::Sprite m_sprite;
	sf::Event m_event;
	sf::Font m_infoFont;
	sf::String m_infoText;
#endif

};

}; // namespace

#endif